package com.cn.demo.util;

public enum RequestResultCode {
    SUCCESS(0, "成功"),
    ERROR(1, "错误"),
    COMET_TIMEOUT(2, "comet_timeout"),
    MEMBER_COMET_TIMEOUT(2, "网络异常,请重试"),
    TIMEOUT(3, "timeout"),
    NETWORK_ERROR(4, "网络异常,请稍候再试"),
    SYSTEM_ERROR(5, "服务异常,请联系客服!"),
    ALLOW_AMOUNT_ERROR(6, "单笔支付金额超过限制!"),
    UPLOAD_FILE_READ_ERROR(7, "上传文件读取失败"),
    UPLOAD_FILE_READ_FORMAT_ERROR(8, "上传文件格式错误"),
    GET_NULL(9, "没有找到数据"),

    //----seckill start 1001
    SECKILL_NOT_EXIST(1000, "不存在"),
    SECKILL_READY(1001, "准备中"),
    SECKILL_DOING(1002, "进行中"),
    SECKILL_FINISH(1003, "已结束"),
    SECKILL_CANCEL(1004, "已取消"),
    SECKILL_REPEAT(1005, "重复失败"),
    SECKILL_FAST(1006, "速度太快"),
    SECKILL_QUEUE(1007, "排队中...请稍后"),
    SECKILL_PAY(1008, "秒杀成功，请支付"),
    //----seckill end

    ;

    private Integer errorCode;
    private String errorMessage;

    private RequestResultCode(Integer errorCode, String errorMessage) {
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    /**
     * 通过代码获取message
     *
     * @param code
     * @return java.lang.String
     * @author: wangjf
     * @createTime: 2019/11/21 14:22
     */
    public static String getErrorMessage(Integer code) {
        for (RequestResultCode state : RequestResultCode.values()) {
            if (state.getErrorCode().equals(code)) {
                return state.errorMessage;
            }
        }
        return null;
    }

    public Integer getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(Integer errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

}

